/*   1:    */ package org.htmlcleaner;
/*   2:    */ 
/*   3:    */ import java.io.IOException;
/*   4:    */ import java.io.Writer;
/*   5:    */ import java.util.HashSet;
/*   6:    */ import java.util.Map;
/*   7:    */ import java.util.Map.Entry;
/*   8:    */ import java.util.Set;
/*   9:    */ import java.util.TreeSet;
/*  10:    */ 
/*  11:    */ public class EpublibXmlSerializer
/*  12:    */   extends SimpleXmlSerializer
/*  13:    */ {
/*  14:    */   private String outputEncoding;
/*  15:    */   
/*  16:    */   public EpublibXmlSerializer(CleanerProperties paramCleanerProperties, String outputEncoding)
/*  17:    */   {
/*  18: 14 */     super(paramCleanerProperties);
/*  19: 15 */     this.outputEncoding = outputEncoding;
/*  20:    */   }
/*  21:    */   
/*  22:    */   protected String escapeXml(String xmlContent)
/*  23:    */   {
/*  24: 19 */     return xmlContent;
/*  25:    */   }
/*  26:    */   
/*  27:    */   protected void serializeOpenTag(TagNode tagNode, Writer writer, boolean newLine)
/*  28:    */     throws IOException
/*  29:    */   {
/*  30: 30 */     String tagName = tagNode.getName();
/*  31: 32 */     if (Utils.isEmptyString(tagName)) {
/*  32: 33 */       return;
/*  33:    */     }
/*  34: 36 */     boolean nsAware = this.props.isNamespacesAware();
/*  35:    */     
/*  36: 38 */     Set<String> definedNSPrefixes = null;
/*  37: 39 */     Set<String> additionalNSDeclNeeded = null;
/*  38:    */     
/*  39: 41 */     String tagPrefix = Utils.getXmlNSPrefix(tagName);
/*  40: 42 */     if (tagPrefix != null) {
/*  41: 43 */       if (nsAware)
/*  42:    */       {
/*  43: 44 */         definedNSPrefixes = new HashSet();
/*  44: 45 */         tagNode.collectNamespacePrefixesOnPath(definedNSPrefixes);
/*  45: 46 */         if (!definedNSPrefixes.contains(tagPrefix))
/*  46:    */         {
/*  47: 47 */           additionalNSDeclNeeded = new TreeSet();
/*  48: 48 */           additionalNSDeclNeeded.add(tagPrefix);
/*  49:    */         }
/*  50:    */       }
/*  51:    */       else
/*  52:    */       {
/*  53: 51 */         tagName = Utils.getXmlName(tagName);
/*  54:    */       }
/*  55:    */     }
/*  56: 55 */     writer.write("<" + tagName);
/*  57: 57 */     if (isMetaContentTypeTag(tagNode)) {
/*  58: 58 */       tagNode.setAttribute("content", "text/html; charset=" + this.outputEncoding);
/*  59:    */     }
/*  60: 62 */     for (Map.Entry<String, String> entry : tagNode.getAttributes().entrySet())
/*  61:    */     {
/*  62: 63 */       String attName = (String)entry.getKey();
/*  63: 64 */       String attPrefix = Utils.getXmlNSPrefix(attName);
/*  64: 65 */       if (attPrefix != null) {
/*  65: 66 */         if (nsAware)
/*  66:    */         {
/*  67: 69 */           if (definedNSPrefixes == null)
/*  68:    */           {
/*  69: 70 */             definedNSPrefixes = new HashSet();
/*  70: 71 */             tagNode.collectNamespacePrefixesOnPath(definedNSPrefixes);
/*  71:    */           }
/*  72: 73 */           if (!definedNSPrefixes.contains(attPrefix))
/*  73:    */           {
/*  74: 74 */             if (additionalNSDeclNeeded == null) {
/*  75: 75 */               additionalNSDeclNeeded = new TreeSet();
/*  76:    */             }
/*  77: 77 */             additionalNSDeclNeeded.add(attPrefix);
/*  78:    */           }
/*  79:    */         }
/*  80:    */         else
/*  81:    */         {
/*  82: 80 */           attName = Utils.getXmlName(attName);
/*  83:    */         }
/*  84:    */       }
/*  85: 83 */       writer.write(" " + attName + "=\"" + escapeXml((String)entry.getValue()) + "\"");
/*  86:    */     }
/*  87: 87 */     if (nsAware)
/*  88:    */     {
/*  89: 88 */       Map<String, String> nsDeclarations = tagNode.getNamespaceDeclarations();
/*  90: 89 */       if (nsDeclarations != null) {
/*  91: 90 */         for (Map.Entry<String, String> entry : nsDeclarations.entrySet())
/*  92:    */         {
/*  93: 91 */           String prefix = (String)entry.getKey();
/*  94: 92 */           String att = "xmlns";
/*  95: 93 */           if (prefix.length() > 0) {
/*  96: 94 */             att = att + ":" + prefix;
/*  97:    */           }
/*  98: 96 */           writer.write(" " + att + "=\"" + escapeXml((String)entry.getValue()) + "\"");
/*  99:    */         }
/* 100:    */       }
/* 101:    */     }
/* 102:102 */     if (additionalNSDeclNeeded != null) {
/* 103:103 */       for (String prefix : additionalNSDeclNeeded) {
/* 104:105 */         if (!prefix.equalsIgnoreCase("xml")) {
/* 105:108 */           writer.write(" xmlns:" + prefix + "=\"" + prefix + "\"");
/* 106:    */         }
/* 107:    */       }
/* 108:    */     }
/* 109:112 */     if (isMinimizedTagSyntax(tagNode))
/* 110:    */     {
/* 111:113 */       writer.write(" />");
/* 112:114 */       if (newLine) {
/* 113:115 */         writer.write("\n");
/* 114:    */       }
/* 115:    */     }
/* 116:117 */     else if (dontEscape(tagNode))
/* 117:    */     {
/* 118:118 */       writer.write("><![CDATA[");
/* 119:    */     }
/* 120:    */     else
/* 121:    */     {
/* 122:120 */       writer.write(">");
/* 123:    */     }
/* 124:    */   }
/* 125:    */   
/* 126:    */   private boolean isMetaContentTypeTag(TagNode tagNode)
/* 127:    */   {
/* 128:125 */     return (tagNode.getName().equalsIgnoreCase("meta")) && ("Content-Type".equalsIgnoreCase(tagNode.getAttributeByName("http-equiv")));
/* 129:    */   }
/* 130:    */ }


/* Location:           C:\Users\David\workspace\CosaRaraPorqueSi\main\epublib-tools-3.1.jar
 * Qualified Name:     org.htmlcleaner.EpublibXmlSerializer
 * JD-Core Version:    0.7.0.1
 */